const http = require('http');

const fs = require('fs');



const imageUrl = 'http://photo.chaoxing.com/p/150312381_80'; // 网络图片的URL

const filePath = 'D:\\aimage\image.jpg'; // 保存图片的本地路径



const request = http.get(imageUrl, (response) => {

   if (response.statusCode === 200) {

       const fileStream = fs.createWriteStream(filePath);

       response.pipe(fileStream);

   } else {

       console.error(`下载图片失败：${response.statusCode} ${response.statusMessage}`);

   }

});



request.on('error', (error) => {

   console.error(`下载图片失败：${error.message}`);

});



request.end();

